<?php
#验证登陆信息
session_start();
include 'connect.php';
$name = $_POST['name'];
$password = $_POST['password'];

$res1 = mysqli_query($link,"select * from tb_user where username = '$name'");
if(mysqli_num_rows($res1) == 0){
    echo '<script>alert("用户名不存在,请先注册后再尝试登陆!")</script>';
    echo '<script>location.href = "register.php"</script>';
    return ;
}
$res2 = mysqli_query($link,"select * from tb_user where username = '$name' and password = '$password'");
if(mysqli_num_rows($res2) == 0){
    echo '<script>alert("密码错误！！！")</script>';
    echo '<script>location.href = "login.php"</script>';
    return ;
}

$_SESSION['userName'] = $name;
header("location:index.php");
